package sintactica;

import java.util.ArrayList;

/**
 *
 * @author bufu
 */
public class Simbol {

    public static final int L_INDEX = 4;
    public static final int L_NUME = 10;
    public String nume;
    public static final int L_CLASA = 11;
    public ClsSimbol clasa;
    public static final int L_TIP = 5;
    public TipSimbol tip;
    public static final int L_INDEX_VAL = 5;
    public int index_val;
    public static final int L_ADREL = 5;
    public int adrel;
    public static final int L_DEPLREP = 5;
    public int deplrel;
    public static final int L_NIVEL = 5;
    public int nivel;
    public static final int L_NR_PAR = 5;
    public int nr_par;
    public static final int L_DIM_VAR = 5;
    public int dim_var;
    public static final int L_ADR_START = 5;
    public int adr_start;
    public static final int L_LISTA_PAR = 5;
    public ArrayList<Integer> lista_par;
    public static final int L_NR_LISTA_PAR = 5;
    public int nr_lista_par;
    public static final int L_IND_MIN = 5;
    public int ind_min;
    public static final int L_IND_MAX = 5;
    public int ind_max;
    public static final int L_LISTA_REC = 5;
    public ArrayList<Integer> lista_rec;
    public static final int L_NR_LISTA_REC = 5;
    public int nr_lista_rec;
    public static final int L_INCDOM = 5;
    public int incdom;

    public enum ClsSimbol {

        PROGRAM, CONSTANTA, VARIABILA, TABLOU, STRUCT,
        CAMP_STRUCT, CAMP_PARA, CAMP_PARA_REF,
        FUNCTIE, PROCEDURA;
    }

    public enum TipSimbol {

        INT, REAL, CHAR;
    }

    public static void printSpace(int nr) {
        for (int i = 0; i < nr; i++) {
            System.out.print(" ");
        }
    }

    public String makeForPrint(int index) {
        StringBuilder buff = new StringBuilder();
        addToBuff(buff, index + "", L_INDEX);
        addToBuff(buff, nume, L_NUME);
        addToBuff(buff, clasa.toString(), L_CLASA);
        String strTip = tip != null ? tip.toString() : "_";
        addToBuff(buff, strTip, L_TIP);
        addToBuff(buff, index_val + "", L_INDEX_VAL);
        addToBuff(buff, adrel + "", L_ADREL);
        addToBuff(buff, deplrel + "", L_DEPLREP);
        addToBuff(buff, nivel + "", L_NIVEL);
        addToBuff(buff, nr_par + "", L_NR_PAR);
        addToBuff(buff, dim_var + "", L_DIM_VAR);
        addToBuff(buff, adr_start + "", L_ADR_START);
        String strListaPar = "_";
        if (lista_par != null) {
            strListaPar = "[";
            for (int i : lista_par) {
                strListaPar += i + " ";
            }
            int len = strListaPar.length();
            if (len > 1) {
                strListaPar = strListaPar.substring(0, len - 1);
            }
            strListaPar += "]";
        }
        addToBuff(buff, strListaPar, L_LISTA_PAR);
        addToBuff(buff, nr_lista_par + "", L_NR_LISTA_PAR);
        addToBuff(buff, ind_min + "", L_IND_MIN);
        addToBuff(buff, ind_max + "", L_IND_MAX);
        String strListRec = "_";
        if (lista_rec != null) {
            strListRec = "[";
            for (int i : lista_rec) {
                strListRec += i + " ";
            }
            int len = strListRec.length();
            if (len > 1) {
                strListRec = strListRec.substring(0, len - 1);
            }
            strListRec += "]";
        }
        addToBuff(buff, strListRec, L_LISTA_REC);
        addToBuff(buff, nr_lista_rec + "", L_NR_LISTA_REC);
        addToBuff(buff, incdom + "", L_INCDOM);
        return buff.toString();
    }

    private void addToBuff(StringBuilder buff, String message, int nr) {
        if (message.length() > nr) {
            buff.append(message.substring(0, nr));
        } else {
            buff.append(message);
            int temp = nr - message.length();
            for (int i = 0; i < temp; i++) {
                buff.append(" ");
            }
        }
        buff.append(" ");
    }
}
